<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/jsp/commons/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="/jsp/commons/cssinclude.jsp"></jsp:include>
<jsp:include page="/jsp/commons/scriptinclude.jsp"></jsp:include>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>晶品科技信息管理系统-业务管理</title>

</head>
<body>
	<%--<jsp:include page="/jsp/commons/top.jsp"></jsp:include> --%>
	<div class="mainbox">

		<form method="post" action="${ctx}/business/businessInfoAction!add.do"
			id="frmNoticeAdd">
			<input type="hidden" id="hbActionType" value="${actionType}" />
			<input type="hidden" id="hbType" name="businessInfo.type" value="${projectType}" />
			<c:if test="${actionType eq '1'}">
			<input type="hidden" name="businessInfo.businessInfoId" value="${businessInfo.businessInfoId}" />
			</c:if>
			<div class="main_content">
				<%--<%@include file="/jsp/commons/leftMenu.jsp"%> --%>
				<div class="main_right">
					<!--面包屑 begin-->
					<c:if test="${actionType eq '1' || actionType eq '0' }">
					<div class="main_rightbox">
						<div class="ec_crumb_kc">
							<span><a class="icon_up" href="#">上一页</a><a
								class="icon_index" href="#">首页</a></span>当前位置：首页&nbsp;&gt;&nbsp;
								<c:choose>
								<c:when test="${projectType eq '0' }">
								业务管理&nbsp;&gt;&nbsp;业务信息&nbsp;&gt;&nbsp;
								 </c:when>
								 <c:when test="${projectType eq '1' }">
								 商务管理&nbsp;&gt;&nbsp;商务信息&nbsp;&gt;&nbsp;
								 </c:when>
								</c:choose>
								<c:choose>
								<c:when test="${actionType eq '1'}">
								<em>修改</em>
								</c:when>
								<c:otherwise>
								<em>增加</em>
								</c:otherwise>
								</c:choose>
						</div>
					</div>
					</c:if>
					<!--基本信息 begin-->
					<div class="ty_border">
						<div class="ty_head">
							<span class="icon4"></span>基本信息
						</div>
						<div class="sx_body">
							<dl class="clearfix">
								<dt style="display: none;">基本信息</dt>
								
								<dd>
									<label class="name">客户名称：</label><span class="toname"> 
									 
									<input
										type="hidden" value="${ businessInfo.customerId}" id="customerId"
										name="businessInfo.customerId"  />
								     <input
										type="text"   id="customerName" value="${businessInfo.customerName}"
										name="businessInfo.customerName" title="客户名称"
										 
										class="winput3" />
									</span>
									<button class="searchBtn dingwei" type="button" id="btnCustomerName"></button>
									<div class="fl">
										<em id="customerNameTip"></em>
									</div>
								</dd>

								<dd>
									<label class="name">甲方负责人：</label> <span class="toname">
										<input type="text" id="repairpeopleName" value="${businessInfo.contactName }"
										name="businessInfo.contactName" title="报修联系人" 
										 
										class="winput3" />
									</span>
									<div class="fl">
										<em id="repairpeopleNameTip"></em>
									</div>
								</dd>

								<dd>
									<label class="name">联系电话：</label><span class="toname"><input
										type="text" id="repairPeoplePhone" value="${businessInfo.mobileNum }"
										name="businessInfo.mobileNum" title="报修联系电话"
										 
										class="winput3" /></span>
									<div class="fl">
										<em id="repairPeoplePhoneTip"></em>
									</div>
								</dd>

								 

								<dd>
									<label class="name">业务员：</label><span class="toname">
										<select id="businessMan" name="businessInfo.businessMan" style="border: 1px solid #DDDDDD; color: #999999; float: right; height: 29px; line-height: 29px; padding-left: 5px; width: 225px;">
										<option value="">---请选择---</option>
										<c:forEach items="${lstUsers }" var="orderUser">
									    <option value="${orderUser.userCode }" 
									    <c:if test="${orderUser.userCode eq  businessInfo.businessMan}">
									    selected="selected" 
									    </c:if>>${orderUser.name}</option>
										</c:forEach> 
									</select>
									</span>
									<div class="fl">
										<em id="businessManTip"></em>
									</div>
								</dd>

								<dd>
									<label class="name">任务：</label><span class="toname">
									<textarea rows="30" cols="100" id="duty"
											name="businessInfo.duty" title="主题内容"
											 
											class="winput3">${businessInfo.duty }</textarea>
									</span>
									<div class="fl">
										<em id="receiveDepartTip"></em>
									</div>
								</dd>
								
								<dd>
									<label class="name">跟进情况：</label><span class="toname"> 
										
									<textarea rows="30" cols="100" id="progress"
											name="businessInfo.progress" title="主题内容"
											 
											class="winput3">${businessInfo.progress }</textarea>
										</span>
									<div class="fl">
										<em id="receivePeopleTip"></em>
									</div>
								</dd>

							</dl>
						</div>
					</div>
					<c:if test="${actionType eq '1' || actionType eq '0' }">
					<!--保存取消 begin-->
					<div class="baocun">
						<button id='btnQuit' type="button" class="gybg qxBtn">取消</button>
						<button type="button" id="btnSave" class="gybg saveBtn">保存</button>
					</div>
					</c:if>
				</div>
			</div>
		</form>

	</div>

	<!--客户弹出层 begin-->
	<div id="customerDialog" style="display: none">
	</div>
	
	 

	<!-- JQ -->

	<script type="text/javascript">
	
	    //页面初始化
		$(function(){
			var myDate = new Date();
			       //获取当前年份(2位)
			var y=myDate.getFullYear();    //获取完整的年份(4位,1970-????)
			var m=(myDate.getMonth()+1)<10?"0"+(myDate.getMonth()+1):(myDate.getMonth()+1);       //获取当前月份(0-11,0代表1月)
			var d=myDate.getDate()<10?"0"+myDate.getDate().toString():myDate.getDate();        //获取当前日(1-31)
			var h=myDate.getHours()<10?"0"+myDate.getHours().toString():myDate.getHours();       //获取当前小时数(0-23)
			var m=myDate.getMinutes()<10?"0"+myDate.getMinutes().toString():myDate.getMinutes();     //获取当前分钟数(0-59)
			var s=myDate.getSeconds()<10?"0"+myDate.getSeconds().toString():myDate.getSeconds();     //获取当前秒数(0-59)
			var ml=myDate.getMilliseconds()<10?"0"+myDate.getMilliseconds().toString():myDate.getMilliseconds();      //获取当前毫秒数(0-999)
			$("#projectCode").val(y.toString()+m.toString()+d.toString()+h.toString()+m.toString()+s.toString()+ml.toString());
		});
	
	    //异步加载维修人员
	    $("#btnMaintenanceManId").click( function(){
	    	 
	    	 $.post(
		     		 "${ctx}/user/userAction!initDialog.action", 
		 				{random:Math.random()}, 
		 				function(data){
		 					$("#userDialog").html(data);
							//加载弹出层
		 					art.dialog({
		 					    id: 'msg',
		 					    title: '选择属性',
		 					    content: $("#userDialog").html(),//绑定内容
		 					    ok: function () {
		 					    
		 					    	var manIds=[];
		 					    	var manNames=[];
		 					    	var manMobiles=[];
		 					    	  $('input[name="userSelected"]:checked').each(function(){    
		 					    		  manIds.push( $(this).attr("user_code"));
		 					    		  manNames.push( $(this).attr("user_name"));
		 					    		  manMobiles.push( $(this).attr("user_mobile"));
		 					    		  });    
		 					    	 $("#maintenanceManId").val(manIds.join(","));
		 					    	 $("#maintenanceManName").val(manNames.join(","));
		 					    	 $("#maintenanceManPhone").val(manMobiles.length>0?manMobiles[0]:"");
		 					    },//确定时回调函数
		 					    cancel:true,//取消时回调函数
		 					    lock: true 
		 					});
		 				}
		      
		        );
	    } );
		//异步加载客户名称
		$("#btnCustomerName").click(function() {
			 $.post(
		     		 "${ctx}/customer/customerAction!initCustomersDialog.action", 
		 				{random:Math.random()}, 
		 				function(data){
		 					$("#customerDialog").html(data);
							//加载弹出层
		 					art.dialog({
		 					    id: 'msg',
		 					    title: '选择属性',
		 					    content: $("#customerDialog").html(),//绑定内容
		 					    ok: function () {
		 					    	var selectCustomerObj= $("input[name='customerSelected']:checked");
		 					    	 $("#customerName").val($(selectCustomerObj).attr("customerName"));
		 					    	 $("#customerId").val($(selectCustomerObj).attr("customerId"));
		 					    	 $("#repairpeopleName").val()==""? $("#repairpeopleName").val($(selectCustomerObj).attr("linkman")):$("#repairpeopleName").val();
		 					    	 $("#repairPeoplePhone").val()==""? $("#repairPeoplePhone").val($(selectCustomerObj).attr("contactphone")): $("#repairPeoplePhone").val();
		 					    },//确定时回调函数
		 					    cancel:true,//取消时回调函数
		 					    lock: true 
		 					});
		 				}
		      
		        );
			
			 
		});
		
		function showMsg(dom,msgFlag,str){
			$("#"+dom+"Tip").html(setPrompt(msgFlag,str,"${ctx}"));
			$("#"+dom).focus();
		}
		
		

		//根据状态为来决定是增加还是修改
		$("#btnSave").click(
						function() {
							var strActionType = $("#hbActionType").val();
							if (strActionType != "") {
								if (strActionType == 0) {
									//新增操作
									//验证编码
									if(frmValidator()){
										$("#frmNoticeAdd").attr("action", "${ctx}/business/businessInfoAction!add.action");
										$("#frmNoticeAdd").submit();
									}
									 
								} else if (strActionType == 1) {
									//修改操作
									$("#frmNoticeAdd").attr("action", "${ctx}/business/businessInfoAction!update.action");
									$("#frmNoticeAdd").submit();
								} else {
									alert("系统错误，请联系系统管理员！");
								}
							} else {
								alert("系统错误，请联系系统管理员！");
							}
						});
		
		
		//验证表单
		function frmValidator(){
			var flag=true;
			if($("#repairDate").val()==""){
				flag=false;
				showMsg("repairDate","onError","报修时间不能为空");
			}else{
				$("#repairDateTip").html(setPrompt("onSuccess","输入正确","${ctx}"));
			}
			if($("#customerName").val()==""){
				flag=false;
				showMsg("customerName","onError","客户名称不能为空");
			}else{
				$("#customerNameTip").html(setPrompt("onSuccess","输入正确","${ctx}"));
			}
			if($("#repairpeopleName").val()==""){
				flag=false;
				showMsg("repairpeopleName","onError","报修联系人不能为空");
			}else{
				$("#repairpeopleNameTip").html(setPrompt("onSuccess","输入正确","${ctx}"));
			}
			if($("#repairPeoplePhone").val()==""){
				flag=false;
				showMsg("repairPeoplePhone","onError","报修联系电话");
			}else{
				$("#repairPeoplePhoneTip").html(setPrompt("onSuccess","输入正确","${ctx}"));
			}
			return flag; 
		}

		/**
		 * 验证编码
		 * @param code 编码
		 * @param flag 是否异步
		 */
		function codeValidator(code, flag) {
			var result = false;
			//异步验证
			if (flag == "Y") {
				$.post("${ctx}/syspara/sysparaAction!codeValidator.action", {
					random : Math.random(),
					"syspara.code" : code
				}, function(data) {
					var jsonData = strToJson(data);
					if (jsonData.flag == "success") {
						$("#sysparaCodeTip")
								.html(
										setPrompt("onSuccess", jsonData.data,
												"${ctx}"));
						result = true;
					} else {
						$("#sysparaCodeTip").html(
								setPrompt("onError", jsonData.errorMsg,
										"${ctx}"));
					}
				});
			} else {
				//同步验证
				var url = "${ctx}/syspara/sysparaAction!codeValidator.action";
				var params = {
					"random" : Math.random(),
					"syspara.code" : code
				};
				$.ajax({
					url : url,
					type : 'post',
					data : params,
					async : false,
					dataType : 'json',
					success : function(data) {
						var jsonData = strToJson(data);
						if (jsonData.flag == "success") {
							$("#sysparaCodeTip").html(
									setPrompt("onSuccess", jsonData.data,
											"${ctx}"));
							result = true;
						} else {
							$("#sysparaCodeTip").html(
									setPrompt("onError", jsonData.errorMsg,
											"${ctx}"));
						}
					},
					error : function() {
						alert("系统错误");
						queryCategory();
					}
				});
			}
			return result;
		}

		/**
		 *绑定值改变事件
		 */
		$("#sysparaCode").change(
				function() {
					$("#sysparaCodeTip").html(
							setPrompt("onLoad", "正在验证数据，请稍等", "${ctx}"));
					codeValidator($("#sysparaCode").val(), "Y");
				});

		$(".ctnGdpOptionPanel li").hover(function() {
			$(this).addClass("hover");
		}, function() {
			$(this).removeClass("hover");
		});
		$(".arrowname").click(function() {
			var domUl = $(this).parent().find(".ctnGdpOptionPanelMask");
			var domArrow = $(this).find("span.arrowdown");
			if (domArrow.hasClass("arrowUp")) {
				domArrow.removeClass("arrowUp");
				domUl.show();
			} else {
				domArrow.addClass("arrowUp");
				domUl.hide();
			}
		});
		
		//取消事件
		$("#btnQuit").click(function(){
			art.dialog.confirm('你确认放弃页面操作，返回列表？', function(){
				location.href ="${ctx}/business/businessInfoAction!listInit.action";
			}, function(){
			     
			});
		});
	</script>
</body>
</html>